package icu.groot.alan.util;

import cn.hutool.core.date.DatePattern;
import org.apache.commons.lang3.StringUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Map;
import java.util.WeakHashMap;
public class Alan {
    public static final String FORMAT_LOCAL_DATE = "yyyy-MM-dd";
    public static final String FORMAT_LOCAL_DATE_TIME = "yyyy-MM-dd HH:mm:ss";
    public static final String FORMAT_LOCAL_TIME = "HH:mm:ss";

    public static void main(String[] args) throws ParseException {
        String s1 = "2023-02-03T22:21";
        s1 = s1.replace("T", " ");
        s1 += ":00";
        System.out.println(Alan.localDateTimeStrToTimestamp(s1, "yyyy-MM-dd HH:mm:ss"));
        long dateInt = System.currentTimeMillis() / 1000;
        System.out.println(dateInt);
    }

//    /**
//     * 日期转换成Java字符串
//     * @param date
//     * @return str
//     */
//    public static String DateToStr(Date date) {
//
//        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        String str = format.format(date);
//        return str;
//    }
//
//    /**
//     * 字符串转换成日期
//     * @param str
//     * @return date
//     */
//    public static Date StrToDate(String str) throws ParseException {
//
//        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
//        Date date = null;
//        date = format.parse(str);
//        return date;
//    }

    public static LocalDateTime strToLocalDateTime(String dateTimeStr, String format){
        return LocalDateTime.parse(dateTimeStr,DateTimeFormatter.ofPattern(format));

    }

    public static LocalDate strToLocalDate(String dateTimeStr, String format){
        return LocalDate.parse(dateTimeStr,DateTimeFormatter.ofPattern(format));

    }

    public static String localDateTimeToStr(LocalDateTime localDateTime, String format){
        String localDateTimeStr = DateTimeFormatter.ofPattern(format).format(localDateTime);
        return localDateTimeStr;
    }

    public static String timestampToStr(long timestamp, String format){
        Instant instant = Instant.ofEpochMilli(timestamp);
        return DateTimeFormatter.ofPattern(format).format(LocalDateTime.ofEpochSecond(timestamp, 0, ZoneOffset.ofHours(8)));
    }

    public static long localDateTimeStrToTimestamp(String localDateTimeStr, String format){
        return LocalDateTime.parse(localDateTimeStr,DateTimeFormatter.ofPattern(format)).toEpochSecond(ZoneOffset.ofHours(8));
    }
//    public static long datetimeToTimestamp(LocalDateTime ldt){
//        long timestamp = ldt.toInstant(ZoneOffset.of("+8")).toEpochMilli();
//        return timestamp;
//    }
}
